#include "mainwindow.h"

#include <QApplication>
#include <QMessageBox>
#include <QSharedMemory>
#include <Common/SysEnv.h>
#include <DeviceManager/types.h>
#include <DeviceManager/enums.h>
#include <SaveLog/savelog.h>
#include <QDebug>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    // 设置应用程序图标
    QIcon appIcon;

    appIcon.addFile(":/icon/app.ico");
    a.setWindowIcon(appIcon);
    // 注册元类型

    qRegisterMetaType<ProcessParams>("ProcessParams");
    qRegisterMetaType<DeviceProtocol::IPCCommand>("DeviceProtocol::IPCCommand");

    qRegisterMetaType<s_PreProcess3DSResultPara>("s_PreProcess3DSResultPara");
    qRegisterMetaType<s_DefectPlateBRtsPara>("s_DefectPlateBRtsPara");
    qRegisterMetaType<s_LzppRtsPara>("s_LzppRtsPara");
    qRegisterMetaType<s_Image3dS>("s_Image3dS");
    qRegisterMetaType<s_DevicesInfo>("s_DevicesInfo");

    // 任务
    qRegisterMetaType<HardwareTaskQueue>("HardwareTaskQueue");
    qRegisterMetaType<TaskExecutionResult>("TaskExecutionResult");
    SysEnv::instance().setConfigInAppDir();


    // 设置应用程序信息
    QApplication::setApplicationName("铜离子系统中间件");
    QApplication::setApplicationVersion("1.1.0");



    // 设置中文字体（简化版）
    QFont font;
    font.setFamily("Microsoft YaHei");  // 微软雅黑，Windows系统通用
    font.setPointSize(9);
    a.setFont(font);

    ///设置是否开启日志上下文打印比如行号、函数等
    SaveLog::Instance()->setUseContext(true);
    ///设置文件存储目录
    SaveLog::Instance()->setPath(qApp->applicationDirPath() + "/log");
    SaveLog::Instance()->deleteLocalLog();
    SaveLog::Instance()->start();
    SaveLog::Instance()->setMaxSize(1024*10);


    /// 检测是否重复运行程序
    static QSharedMemory *sharMemory = new QSharedMemory("MzPoliShine.exe");
    if(sharMemory->attach())
    {
        QMessageBox::information(NULL,"Warning",QObject::tr("程序已经在运行!"));
        return 0;
    }
    sharMemory->create(1);

    MainWindow w;
    w.setWindowTitle("铜离子系统中间件 v1.1.0 Best");
    w.show();
    return a.exec();
}
